package mysql

import (
	"shuqi-novel/shuqirpc/shuqirpc"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Username string `grom:"type:varchar(30);not null;comment:'用户名'"`
	Password string `grom:"type:varchar(32);not null;comment:'密码'"`
}

func (u *User) FindUserByUsername(db *gorm.DB, username string) error {
	return db.Debug().Where("username=?", username).First(u).Error
}

func (u *User) UserList(db *gorm.DB, in *shuqirpc.UserListRequest, lists []*shuqirpc.UserList) ([]*shuqirpc.UserList, error) {
	err := db.Debug().Table("users").Select("users.id as user_id,username,password").
		Scopes(Paginate(int(in.Page), int(in.Size))).Find(&lists).Error
	return lists, err
}
